package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// TerminalScreencapLog 终端截图记录
type TerminalScreencapLog struct {
	ID            string `json:"id" gorm:"primaryKey;column:id;type:int;size:64;comment:主键"`
	RobotID       string `json:"robot_id" gorm:"column:robot_id;idx_created_at,priority:2;type:string;size:40;comment:设备id"`
	TerminalType  string `json:"terminal_type" gorm:"column:terminal_type;type:string;size:40;comment:设备类型"`
	ScreencapName string `json:"screencap_name" gorm:"column:screencap_name;type:string;size:40;comment:截图名称"`
	UserID        string `json:"user_id" gorm:"column:user_id;type:bigint;size:64;comment:操作用户"`
	CreatedAt     int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;index:idx_created_at,priority:1;type:int;size:64;comment:创建时间"`
}

// TableName 表名称
func (TerminalScreencapLog) TableName() string {
	return "terminal_screencap_log"
}

// BeforeCreate 自增id
func (t *TerminalScreencapLog) BeforeCreate(tx *gorm.DB) (err error) {
	if t.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	t.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &TerminalScreencapLog{})
}
